<?php

namespace Home\Controller;

use Think\Controller;
use Admin\Model;
class LoginController extends Controller {

    public function index() {
        if (IS_POST) {
            $param = $_POST;
            $user = $param['username'];
            $pwd = strtoupper(md5($param['pwd']));
            $shopAccount = new \Admin\Model\ShopAccountModel();
            $result = $shopAccount->getFind(array('accountname' => $user));
            if (!isset($result) && empty($result)) {
                $this->ajaxReturn(array('code' => 10001, 'msg' => '账号错误', 'data' => array()));
            }
            if ($result['pwd'] != $pwd) {
                $this->ajaxReturn(array('code' => 10002, 'msg' => '密码错误', 'data' => array()));
            }
            if ($result['inuse'] != 1) {
                $this->ajaxReturn(array('code' => 10003, 'msg' => '账户被禁用 请联系管理员', 'data' => array()));
            }
            $_SESSION['account_user_id'] = $result['id'];
            // 更新上架最后登录时间、ip
            $where['id'] = $result['id'];
            $data['lastlogindt'] = date("Y-m-d H:i:s");
            $data['lastloginip'] = $_SERVER['REMOTE_ADDR'];
            $shopAccount->saveData($where, $data);
            $this->ajaxReturn(array('code' => 10000, 'msg' => '登录成功', 'data' => array()));
        } else {
            $this->display("Login/login");
        }
    }

}
